home *** CD-ROM | disk | FTP | other *** search
/ Internet Pratica / IPRAT_01.iso / ASP / ASPapp Portal / admin_luIndustry.asp < prev    next >
Encoding:
Text File  |  2002-03-12  |  8.0 KB  |  348 lines

  1. <!-- #include file="i_utils.asp" -->
  2. <%
  3.  
  4. check_security(1) 
  5.  
  6. %>
  7. <%
  8.     dim ID
  9.     dim Industry
  10.     dim edit_luindustry_sql
  11.     dim view_luindustry_sql
  12.  
  13. sub request_edit_luindustry
  14. ''' request expected input parameters for this form
  15.     ID = request("ID")
  16.     Industry = request("Industry")
  17. end sub
  18. sub request_view_luindustry
  19. ''' request expected input parameters for this form
  20.     ID = request("ID")
  21.     Industry = request("Industry")
  22. end sub
  23.  
  24. sub validate_edit_luindustry
  25. ''' request and validate data entered from this form
  26.     ID = trim(request("ID"))
  27.     Industry = trim(request("Industry"))
  28. end sub
  29. sub validate_view_luindustry
  30. ''' request and validate data entered from this form
  31.     ID = trim(request("ID"))
  32.     Industry = trim(request("Industry"))
  33. end sub
  34.  
  35.  
  36. sub db_select_edit_luIndustry
  37.     sql = "SELECT " & _ 
  38.     "ID, " & _ 
  39.     "Industry FROM luIndustry" & _ 
  40.     " WHERE " & _ 
  41.     "luIndustry.ID = " & to_sql(ID,"number") & ""
  42.     on error resume next
  43.     set rs = cn.Execute(sql)
  44.     if err.number <> 0 then
  45.         b_error = true
  46.     elseif rs.EOF then
  47.         b_results = false
  48.     else
  49.         ID = rs("ID")
  50.         Industry = rs("Industry")
  51.     end if
  52.     rs.Close
  53.     on error goto 0
  54. end sub
  55. sub db_insert_edit_luIndustry
  56.     sql = "INSERT INTO luIndustry" & _ 
  57.     "(" & _ 
  58.     "Industry" & _ 
  59.     ") VALUES (" & to_sql(Industry,"text") & ")" & _ 
  60.     ""
  61.     'response.write sql
  62.     on error resume next
  63.     cn.Execute(sql)
  64.     if err.Number <> 0 then
  65.         b_error = true
  66.     else
  67.         set rs = cn.Execute("SELECT @@IDENTITY")
  68.         ID = rs(0)
  69.         rs.Close
  70.     end if
  71.     on error goto 0
  72. end sub
  73. sub db_update_edit_luIndustry
  74.     sql = "UPDATE luIndustry SET " & _ 
  75.     "Industry = " & to_sql(Industry,"text") & " WHERE " & _ 
  76.     "ID = " & to_sql(ID,"number") & ""
  77.     'response.write sql
  78.     on error resume next
  79.     cn.execute(sql)
  80.     if err.number <> 0 then
  81.         b_error = true
  82.     end if
  83.     on error goto 0
  84. end sub
  85. sub db_delete_edit_luIndustry
  86.     sql = "DELETE FROM luIndustry" & _ 
  87.     " WHERE " & _ 
  88.     "ID = " & to_sql(ID,"number") & ""
  89.     'response.write sql
  90.     on error resume next
  91.     cn.Execute(sql)
  92.     if err.number <> 0 then
  93.         b_error = true
  94.     end if
  95.     on error goto 0
  96. end sub
  97. sub db_select_view_luIndustry
  98.     view_luIndustry_sql = "SELECT " & _ 
  99.     "ID, " & _ 
  100.     "Industry FROM luIndustry" & _ 
  101.     ""
  102.     if request("sortby") <> "" AND inStr(lcase(view_luIndustry_sql),"order by") = 0 then view_luIndustry_sql = view_luIndustry_sql + " ORDER BY " & request("sortby")
  103. end sub
  104. sub db_update_view_luIndustry
  105.     sql = "UPDATE  SET " & _ 
  106.     "Industry = " & to_sql(Industry,"text") & ""
  107.     'response.write sql
  108.     on error resume next
  109.     cn.execute(sql)
  110.     if err.number <> 0 then
  111.         b_error = true
  112.     end if
  113.     on error goto 0
  114. end sub
  115. sub db_delete_view_luIndustry
  116.     sql = "DELETE FROM " & _ 
  117.     ""
  118.     'response.write sql
  119.     on error resume next
  120.     cn.Execute(sql)
  121.     if err.number <> 0 then
  122.         b_error = true
  123.     end if
  124.     on error goto 0
  125. end sub
  126.  
  127. do_search = request("do_search")
  128. ''' request form keys
  129. ID = request("ID")
  130. ''' request action
  131. action = lcase(request("action"))
  132. ''' action case handler
  133. select case action
  134.  
  135. case "select_edit_luindustry"
  136. '  select the requested key record from database
  137. if ID <> "" then
  138.     db_select_edit_luIndustry
  139. else
  140.     b_error = true
  141.     error_list.add "edit_edit_luIndustry", "Specify record to select."
  142. end if
  143.  
  144.  
  145. case "insert_edit_luindustry"
  146. '  request form data and insert a new record into database
  147.  
  148. validate_edit_luindustry
  149. if not b_error then
  150.     db_insert_edit_luindustry
  151. end if
  152.  
  153.  
  154.  
  155. case "update_edit_luindustry"
  156. '  request form data and update an existing database record
  157. validate_edit_luindustry
  158. if not b_error then
  159. if ID <> "" then
  160.     db_update_edit_luindustry
  161. else
  162.     b_error = true
  163.     error_list.add "update_edit_luindustry", "Specify record to update."
  164. end if
  165. end if
  166.  
  167.  
  168. case "delete_edit_luindustry"
  169. '  delete the requested key database record
  170. if ID <> "" then
  171.     db_delete_edit_luindustry
  172.     response.redirect request.servervariables("script_name") & "?msg=The+record+was+deleted."
  173. else
  174.     b_error = true
  175.     error_list.add "delete_edit_luindustry", "Specify record to delete."
  176. end if
  177.  
  178.  
  179. case "update_view_luindustry"'  request form data from edit grid to update existing database records
  180. '  this case is only created when a grid form's 'update' property is enabled
  181. validate_view_luindustry
  182. if not b_error then
  183. if  then
  184.     db_update_view_luindustry
  185. else
  186.     b_error = true
  187.     error_list.add "update_view_luindustry", "Specify record to update."
  188. end if
  189. end if
  190.  
  191.  
  192. case "delete_view_luindustry"'  request form data from edit grid to delete existing database records
  193. '  this case is only created when a grid form's 'update' property is enabled
  194. if  then
  195.     db_delete_view_luindustry
  196.     response.redirect request.servervariables("script_name") & "?msg=The+record+was+deleted."
  197. else
  198.     b_error = true
  199.     error_list.add "delete_view_luindustry", "Specify record to delete."
  200. end if
  201.  
  202.  
  203. end select
  204.  
  205. '  no action was specified, so handle the default case(s)
  206. if ID <> "" then
  207.     db_select_edit_luindustry
  208. end if
  209.  
  210. db_select_view_luindustry
  211.  
  212. %>
  213.  
  214. This table might be useful for associating users and industries.
  215. <P><br>
  216. <%
  217. display_errs
  218. display_msg
  219. %>
  220.  
  221. <table class='headerTable'>
  222. <tr>
  223. <td class='headerTD'>
  224. Industries Lookup
  225. </td>
  226. </tr>
  227. </table>
  228. <table  >
  229. <form name="edit_luIndustry" action="luIndustry.asp" method="GET" >
  230. <tr>
  231.     <td class='fieldTD'><a href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =page_no %>&sortby=Industry" class=fieldFont title="">Industry</a></td>
  232. </tr>
  233.         
  234.         <input type=hidden name="ID" value="<% =ID %>">
  235.         
  236. <tr>
  237.     <td class='dataTD' >
  238.         <input type=text  name="Industry" size="" maxlength="50" value="<% =Industry%>">
  239.     </td>
  240. </tr>
  241. <tr>
  242.     <td align=right class=dataTD colspan=2>
  243.     <% if ID = "" then %><input type=submit name=insert_button value=insert> <% end if %>
  244.     <% if ID <> "" then %><input type=submit name=delete_button value=delete onclick="document.edit_luIndustry.action.value = 'delete_edit_luIndustry'"> <% end if %>
  245.     <% if ID <> "" then %><input type=submit name=update_button value=update><% end if %>
  246.     </td>
  247. <input type=hidden name="action" value="<% if ID <> "" then %>update<% else %>insert<%end if %>_edit_luIndustry"></tr>
  248.  
  249. </form>
  250. </table>
  251.  
  252.  
  253. <%
  254.  
  255. page_no = request("page_no")
  256. if page_no = "" then page_no = 1
  257.  
  258. if view_luIndustry_sql <> "" then
  259.     cmd.CommandText = view_luIndustry_sql
  260.     rs.Filter = ""
  261.     rs.CursorLocation = 3
  262.     rs.CacheSize = 5
  263.     rs.Open cmd
  264.     if not rs.EOF then
  265.             rs.MoveFirst
  266.             max_count = cInt(rs.PageCount)
  267.             num_recs = rs.RecordCount
  268.             rs.AbsolutePage = page_no
  269.             results = true
  270.     else
  271.         results = false
  272.         rs.Close
  273.     end if
  274. else
  275.     results = false
  276. end if
  277. rec_count = 0
  278.  
  279. %>
  280.  
  281. <table class='headerTable'>
  282. <tr>
  283. <td class='headerTD'>
  284. luIndustry
  285. </td>
  286. </tr>
  287. </table>
  288. <%
  289.  
  290. if results = true then
  291.  
  292. %>
  293.  
  294. <table  >
  295. <form name="view_luIndustry" action="luIndustry.asp" method="GET" >
  296. <tr>
  297.     <td class='fieldTD'><a href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =page_no %>&sortby=ID" class=fieldFont title="">ID</a></td>
  298.     <td class='fieldTD'><a href="<% =request.servervariables("script_name") %>?<% =request_string %>page_no=<% =page_no %>&sortby=Industry" class=fieldFont title="">Industry</a></td>
  299. </tr>
  300. <%
  301.  
  302. do while not rs.EOF
  303.  
  304. ':: read db record
  305. on error resume next
  306. ID = rs("ID")
  307. Industry = rs("Industry")
  308. on error goto 0
  309.  
  310. %>
  311. <tr>
  312.     <td class='dataTD' >
  313.         <a href="luIndustry.asp?ID=<%=ID%>"><% =ID %></a>
  314.     </td>
  315.     <td class='dataTD' >
  316.         <input type=text  name="Industry" size="" maxlength="50" value="<% =Industry%>">
  317.     </td>
  318. </tr>
  319. <%
  320.  
  321. rs.MoveNext
  322. rec_count = rec_count + 1
  323. loop
  324. rs.Close
  325.  
  326. %>
  327. <tr class=formtr>
  328.     <td class=dataTD align=right colspan=2>
  329.     <input type=submit name=update_button value=update>
  330.     </td>
  331. </tr>
  332. <input type=hidden name="action" value="update_view_luindustry">
  333.  
  334. </form>
  335. </table>
  336. <%
  337.  
  338. else
  339.  
  340. %>
  341.  
  342.     
  343.  
  344. <%
  345.  
  346. end if
  347.  
  348. %>
  349.  
  350.  
  351.  
  352.  
  353.  
  354. <%
  355. ':: assure that any db resources are freed
  356. on error resume next
  357. rs.Close
  358. set rs = NOTHING
  359. cn.Close
  360. set cn = NOTHING
  361. user_cn.Close
  362. set user_cn = NOTHING
  363. on error goto 0
  364. %>
  365.